package com.interview.service.impl;

import com.interview.entity.QuesUser;
import com.interview.entity.param.SelectQuesUserParam;
import com.interview.mapper.QuesUserMapper;
import com.interview.service.QuesUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @author JiangYingbo
 */
@Service
public class QuesUserServiceImpl implements QuesUserService {
    @Autowired
    private QuesUserMapper quesUserMapper;

    @Override
    public List<QuesUser> selectQuesUserList(SelectQuesUserParam param) {
        // 组装查询条件
        QuesUser condition = new QuesUser();
        condition.setUserId(param.getUserId());
        condition.setQuesStatus(param.getQuesStatus());
        condition.setQuesDesc(param.getQuesDesc());
        // 根据条件查询问题用户表
        return quesUserMapper.select(condition);
    }

    @Override
    public void insertQuesUser(QuesUser quesUser) {
        int result = quesUserMapper.insert(quesUser);
        if (result <= 0) {
            throw new RuntimeException("插入问题用户表失败！");
        }
    }

    @Override
    public int deleteQuesUserByUserId(Integer quesUserId) {
        int result = quesUserMapper.delete(quesUserId);
        if (result <= 0) {
            throw new RuntimeException("删除问题用户表失败！");
        }
        return result;
    }

    @Override
    public QuesUser quesUserInfo(Integer quesUserId) {
        // 组装用户查询条件
        QuesUser condition = new QuesUser();
        condition.setQuesUserId(quesUserId);
        return quesUserMapper.select(condition).get(0);
    }

    @Override
    public int updateQuesUser(QuesUser quesUser) {
        int res = quesUserMapper.updateUserReply(quesUser);
        if (res <= 0) {
            throw new RuntimeException("更新失败！");
        }
        return res;
    }
}
